"""功耗采样后端抽象基类"""

from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Optional


class PowerBackend(ABC):
    """功耗采样后端抽象基类"""
    
    @abstractmethod
    def init(self, device_id: int = 0) -> bool:
        """
        初始化后端
        
        Args:
            device_id: 设备ID
            
        Returns:
            bool: 初始化是否成功
        """
        pass
    
    @abstractmethod
    def sample(self) -> Optional[float]:
        """
        采样当前功率
        
        Returns:
            Optional[float]: 功率值（毫瓦 mW），如果采样失败返回 None
        """
        pass
    
    @abstractmethod
    def cleanup(self):
        """清理资源"""
        pass
    
    @abstractmethod
    def get_name(self) -> str:
        """返回后端名称"""
        pass
    
    @staticmethod
    @abstractmethod
    def is_available() -> bool:
        """检查后端是否可用"""
        pass

